package com.qingke.memo.command.system;

import com.qingke.memo.command.SystemCommand;
import com.qingke.memo.pojo.Memo;
import com.qingke.memo.unit.MConsole;

public class AlterMemo extends SystemCommand {

	@Override
	public void execute() {
		int id=MConsole.getInt("input memo id:");
		if(!dao.isMemoExistById(id)){
			MConsole.println("the memo is not exist.");
			return ;
		}
		Memo memo=dao.selectMemoById(id);
		while(true){
			String str=MConsole.prompt("alter (1.title,2.content,3.confirm alter)>");
			if("1".equalsIgnoreCase(str))
				title(memo);
			else if("2".equalsIgnoreCase(str))
				content(memo);
			else if("3".equalsIgnoreCase(str))
				break;
			else
				MConsole.println("err input");
		}
		
		boolean isSuccess=dao.updateMemo(memo);
		if(isSuccess)
			MConsole.println("update memo success.");
		else
			MConsole.println("update memo failed.");
	}
	
	private void title(Memo memo){
		String title=MConsole.promptNotEmpty("new title:");
		memo.setTitle(title);
	}
	
	private void content(Memo memo){
		String content=MConsole.promptCanEmpty("new content:");
		memo.setContent(content);
	}

}
